package com.zhuchaooasystem.presenter.home.serviceschedule;

import android.app.Activity;

import com.zhuchaooasystem.api.HttpFactory;
import com.zhuchaooasystem.api.RxResultHelper;
import com.zhuchaooasystem.base.BasePresenter;
import com.zhuchaooasystem.base.SchedulersCompat;
import com.zhuchaooasystem.entity.ServiceProgressEntity;

import java.util.HashMap;
import java.util.Map;

import rx.Subscription;
import rx.functions.Action1;

/**
 * Created by zhangyajiang on 2016/12/22.
 */

public class ServiceSchedulePresenter extends BasePresenter<ServiceScheduleContract.View> implements ServiceScheduleContract.Presenter {

    public ServiceSchedulePresenter(Activity activity, ServiceScheduleContract.View view) {
        super(activity, view);
    }


    @Override
    public void downServiceListData(String id) {
        final Map<String, String> map = new HashMap<>();
        map.put("serviceid", id);

        showLoading();
        Subscription subscription = HttpFactory.getHttpApi().getServiceProgress(map)
                .compose(SchedulersCompat.applyIoSchedulers())
                .compose(RxResultHelper.handleResult())
                .subscribe(new Action1<Object>() {
                    @Override
                    public void call(Object o) {
                        ServiceProgressEntity entity = (ServiceProgressEntity) o;

                        if (entity != null) {
                            mView.showServiceListData(entity);
                            mView.showGoodListData(entity);
                        }

                        LoadingDiaogDismiss();

                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        LoadingDiaogDismiss();

                        handleError(throwable);
                    }
                });
        addSubscrebe(subscription);
    }
}
